
use async_graphql::*;
use futures::executor::block_on;
use std::future::Future;

struct Query;

#[Object]
impl Query {
    /// Returns the sum of a and b
    async fn add(&self, a: i32, b: i32) -> i32 {
        a + b
    }
}


pub async fn gsample()->Option<String>{
    let schema = Schema::new(Query, EmptyMutation, EmptySubscription);
    let res = schema.execute("{ add(a: 10, b: 20) }").await;
    let json = serde_json::to_string(&res);
    json.ok()
}



pub  fn gsample0(query:String)-> Response{
    let schema = Schema::new(Query, EmptyMutation, EmptySubscription);
    let res = schema.execute(query);
    block_on(res)
}


pub  fn gsample1()-> Response{
    let schema = Schema::new(Query, EmptyMutation, EmptySubscription);
    let res = schema.execute("{ add(a: 10, b: 20) }");
    block_on(res)
}


pub async  fn gsample2()-> async_graphql::Response {
    let schema = Schema::new(Query, EmptyMutation, EmptySubscription);

    let res = schema.execute("{ add(a: 10, b: 20) }").await;

    let query = Request::new(
        r#"
            query QueryWithVariables($value1: MyEnum, $value2: MyEnum, $value3: MyEnum) {
                a: value(value: $value1)
                b: value(value: $value2)
                c: value(value: $value3)
            }
        "#,
    )
    .variables(Variables::from_json(serde_json::json!({
        "value1": "A",
        "value2": "B",
        "value3": "C",
    })));
    
    res

}

